/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SComplaintConverter.java
 * Created：		2016年8月21日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.repair.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.AAttachmentConverter;
import com.thor.palmmall.rest.common.AOperateInfoConverter;
import com.thor.palmmall.rest.common.ASourceBillConverter;
import com.thor.palmmall.rest.common.AWorkOrderConverter;
import com.thor.palmmall.rest.common.OperateInfoConverter;
import com.thor.palmmall.rest.patrol.repair.converter.ATransferInfoConverter;
import com.thor.palmmall.rest.repair.ARepairBill;
import com.thor.palmmall.rest.repair.ARepairEvaluation;
import com.thor.palmmall.spi.maintain.SMaintainBill;

/**
 * @author wolv
 *
 */
public class ARepairBillConverter implements Converter<SMaintainBill, ARepairBill> {

  public static ARepairBillConverter getInstance() {
    if (instance == null)
      instance = new ARepairBillConverter();
    return instance;
  }

  private static ARepairBillConverter instance;

  private ARepairBillConverter() {
  }

  @Override
  public ARepairBill convert(SMaintainBill source) {
    if (source == null)
      return null;

    ARepairBill target = new ARepairBill();
    target.setAfterPictures(
        ConverterUtil.convert(source.getAfterPictures(), AAttachmentConverter.getInstance()));
    target.setAppointmentTime(source.getAppointmentTime());
    target.setBeforePictures(
        ConverterUtil.convert(source.getBeforePictures(), AAttachmentConverter.getInstance()));
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setContactInfo(source.getContactInfo());
    target.setContract(UCN.newInstance(source.getContract()));
    if (source.getEvaluation() != null)
      target.setEvaluation(ARepairEvaluation.valueOf(source.getEvaluation().name()));
    target.setMaintainBeginTime(source.getMaintainBeginTime());
    target.setMaintainEndTime(source.getMaintainEndTime());
    target.setMaintainContent(source.getMaintainContent());
    target.setMaintainType(source.getMaintainType());
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setRepairRecord(ARepairRecordConverter.getInstance().convert(source.getRepairRecord()));
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setTenantEvaluation(source.getTenantEvaluation());
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setMaintainAddress(source.getMaintainAddress());
    target.setSolve(source.getSolve());
    target.setSourceBill(ASourceBillConverter.getInstance().convert(source.getSourceBill()));
    target.setWorkOrder(AWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    target.setType(source.getType());
    target.setHandler(source.getHandler());
    target.setReportDate(source.getReportDate());
    target.setMaintainObject(source.getMaintainObject());
    target.setApplicant(source.getApplicant());
    target.setEvaluateUser(source.getEvaluateUser());
    target.setEvaluateTime(source.getEvaluateTime());
    target.setTransferOther(source.getTransferOther());
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), AAttachmentConverter.getInstance()));
    target.setTransferInfos(
        ConverterUtil.convert(source.getTransferInfos(), ATransferInfoConverter.getInstance()));
    target.setAbortMsg(source.getAbortMsg());
    target.setCreateInfo(AOperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target
        .setLastModifyInfo(AOperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmState(source.getBpmState());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setRemark(source.getRemark());
    target.setCompletionInfo(source.getCompletionInfo());
    target.setSubmitTime(source.getSubmitTime());
    target.setDealTime(source.getDealTime());
    target.setDealUser(source.getDealUser());
    target.setFinishTime(source.getFinishTime());
    return target;
  }
}
